package com.sumainfor.pc.market.service;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.ParamsCommon;
import com.sumainfor.pc.market.dao.MaintenanceHouConMapper;
import org.redisson.api.annotation.RRemoteAsync;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

/**
 * <p>
 * 通过房源配置主表编号查询房源信息
 * <p>
 *
 * @author: zhoucong
 * @create: 2019-06-03 19:50
 **/
@Service
public class MaintenanceHouConService implements Serializable {

    private ReentrantLock lock = new ReentrantLock(false);
    Logger log = LoggerFactory.getLogger(MaintenanceHouConService.class);

    @Autowired
    MaintenanceHouConMapper maintenanceHouConMapper;

    /**
    * <p>
    * 同过房源你配置主表编号查询房源信息
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    public JsonResult getHouConList(Map<String,Object> params){
        JsonResult result = new JsonResult();
        System.out.println("接受的参数"+params);
        return result.put(maintenanceHouConMapper.getHouConList(params));
    }


    /**
    * <p>
    * 通过房源编号查询房源信息
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    public JsonResult getHouIdLists(Map<String,Object> params){
        JsonResult result = new JsonResult();
        return result.put(maintenanceHouConMapper.getHouIdLists(params));
    }


    @Transactional(rollbackFor = Exception.class)
    public JsonResult updatePayment(Map<String,Object> params){

        JsonResult result = new JsonResult();
        lock.lock();

        try {
            params.put("term","3");//1 租客端 2市场部 3 工程部 4运营部 5财务部 6总经办 7发展部
            params.put("fnc",
                    this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
            ParamsCommon.commonUpdateParms(params);
            Integer cout = maintenanceHouConMapper.updatePayment(params);
            if (cout>0){
              result.putSuccess("修改房源智能成功");

            }else {
              return  result.putFailed("修改房源智能失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        } finally {
            lock.unlock();

        }
         return result;

    }
}
